package com.huluobo.day_1_lifecycledemo.databinding;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.huluobo.day_1_lifecycledemo.R;
import com.huluobo.day_1_lifecycledemo.viewbinding.BaseActivity;

public class UserActivity extends BaseActivity<ActivityUserBinding> {

    @Override
    protected ActivityUserBinding getViewBinding() {
        return ActivityUserBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        viewBinding.userConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                User user = getUser();
                viewBinding.setUser(user);
            }
        });
    }

    private User getUser() {
        return new User(getUserName(), getUserId(), "https://pic3.zhimg.com/v2-20ec1b6c885a660ff3c68238fce5d55b_r" +
                ".jpg?source=1940ef5c%EF%BF%BC");
    }

    private String getUserId() {
        return viewBinding.edUserId.getText().toString();
    }

    private String getUserName() {
        return viewBinding.edUserName.getText().toString();
    }
}